<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="1000" :close-on-press-escape="mode != 'show' ? false : true" destroy-on-close @closed="$emit('closed')" :close-on-click-modal="false">
        <el-container>
            <el-main class="nopadding"> 
                <scTable ref="table" :apiObj="apiObj" row-key="id" border @setExtend="setExtend" height="500" :params="query">
                    <el-table-column type="selection" width="50" align="center"></el-table-column>
                    <el-table-column label="入库单号" prop="flower">
                        <template #default="{row}">
                            <el-tag :type="row.input_type == 1 ? 'info' : row.input_type == 2 ? 'primary' : row.input_type == 3 ? 'success' : 'warning'">{{row.input_type == 1 ? '采购单入库' : row.input_type == 2 ? '染色单入库' : row.input_type == 3 ? '加工单入库' : '其他入库'}}</el-tag><br>
                            <el-link :underline="false" type="primary" @click="table_show_hosue(row)">{{ row.order_no }}</el-link>
                        </template>
                    </el-table-column>
                    <el-table-column label="花型" prop="flower" align="center"></el-table-column>
                    <el-table-column label="颜色" prop="color" align="center"></el-table-column>
                    <el-table-column label="冻结库存数量" prop="frozen_stock" align="center" width="120"></el-table-column>
                    <el-table-column label="库存(匹)" prop="stock" align="center" width="120"></el-table-column>
                </scTable>
            </el-main>
        </el-container>
		<template #footer>
			<el-button @click="visible = false">取 消</el-button>
		</template>
        <purchase-house v-if="dialog.purchase" ref="purchaseDialog" @success="handleSuccess" @closed="dialog.purchase = false"></purchase-house>
        <dye-hosue v-if="dialog.dye" ref="dyeDialog" @success="handleSuccess" @closed="dialog.dye = false"></dye-hosue>
        <machin-house v-if="dialog.machin" ref="machinDialog" @success="handleSuccess" @closed="dialog.machin = false"></machin-house>
	</el-dialog>
</template>

<script>
import purchaseHouse from '@/views/business/purchase/arrival/save.vue'
import dyeHosue from '@/views/business/dye/house/save.vue'
import machinHouse from '@/views/business/machining/house/save.vue'
export default {
    props:{
        query: { type: Object, default: () => ({}) },
    },
    components: { purchaseHouse, dyeHosue, machinHouse },
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '新增',
				edit: '编辑',
				show: '查看'
			},
			visible: false,
			apiObj: this.$API.ware.ware.stock_uninspect.house,
            dialog: {
                purchase: false,
                dye: false,
                machin: false,
            },
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
        //搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
        refresh() {
            for (const key in this.search) {
                this.search[key] = null;
            }
            this.$refs.table.upData(this.search)
        },
        table_show_hosue(row){
            let query = {}
            if(row.input_type ==1){
                query = {
                    id: row.purchase_ware_id,
                    purchase_ware_code: row.order_no,
                }
            }else if(row.input_type == 2){
                query = {
                    id: row.purchase_ware_id,
                    purchase_dye_code: row.order_no,
                }
            }else {
                query = {
                    id: row.purchase_ware_id,
                    purchase_ware_code: row.order_no,
                }
            }
            this.dialog[row.input_type == 1 ? 'purchase' : row.input_type == 2 ? 'dye' : 'machin'] = true
            this.$nextTick(() => {
                this.$refs[row.input_type == 1 ? 'purchaseDialog' : row.input_type == 2 ? 'dyeDialog' : 'machinDialog'].open('show').setData(query)
            })
        },
	}
}
</script>

<style></style>
